<?php

class Price {

    private $coins;
    private $potions;

    public function __construct($coins = 0, $potions = 0) {
        $this->coins = $coins;
        $this->potions = $potions;
    }

    public function getData() {
        $data['coins'] = $this->coins;
        $data['potions'] = $this->potions;
        return $data;
    }

    private function getPrice() {
        return array($this->coins, $this->potions);
    }

    public function getCoins() {
        return $this->coins;
    }

    public function getPotions() {
        return $this->potions;
    }

    public function compare($other) {
        if (is_int($other)) {
            $other = new Price($other, 0);
        }
        if (is_array($other)) {
            return new Price($other[0], $other[1]);
        }
        if ($other instanceof Price) {
            if ($this->coins == $other->getCoins() && $this->potions == $other->getPotions())
                return 0;
            else if ($this->coins <= $other->getCoins() && $this->potions <= $other->getPotions())
                return - 1;
            return 1;
        }
        throw new Exception("other is not a price: " . get_class($other));
    }

    public function add($other) {
        $coins = 0;
        $potions = 0;
        if (is_int($other)) {
            $coins = $this->coins + $other;
            $potions = $this->potions;
        } else if (is_array($other)) {
            $coins = $this->coins + $other[0];
            $potions = $this->potions + $other[1];
        } else if ($other instanceof Price) {
            $otherPrice = $other->getPrice();
            $coins = $this->coins + $other->getCoins();
            $potions = $this->potions + $other->getPotions();
        }

        $coins = max(0, $coins);
        $potions = max(0, $potions);
        return new Price($coins, $potions);
    }

}

?>